/*************************************************************
   Copyright(C) 2017 by MartyrCompany
   All rights reserved.
   
   UIControlDataType.cs
   UnityFramework
   
   Created by WuIslet on 2020-11-03.
   
*************************************************************/

using DG.Tweening;
//using Framework.EffectSystem;
using Framework.UI;
//using Framework.UI.OSA;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public struct UIControlDataTypeData
{
    public string name;
    public Type unityType;
    public CtrlItemDataDefaultFormatHelper helper;
}
public class EUIControlDataType
{
    public const string None = "";
    public const string HMI_Text = "HMI_Text";
    public const string HMI_Button = "HMI_Button";
    public const string HMI_Title = "HMI_Title";
    public const string HMI_SlideButton = "HMI_SlideButton";
    public const string HMI_Toggle = "HMI_Toggle";
    public const string HMI_Slider = "HMI_Slider";
    public const string HMI_TabGroupBtn = "HMI_TabGroupBtn";
    public const string HMI_ScrollView = "HMI_ScrollView";
    public const string HMI_HorizontalItem = "HMI_HorizontalItem";
    public const string StaticBluredImg = "StaticBluredImg";
    public const string TextMeshProUGUI = "TextMeshProUGUI";
    public const string DoubleButton = "DoubleButton";
    public const string LPButton = "LPButton";
    public const string Button = "Button";
    public const string OSALScrollView = "OSALScrollView";
    public const string OSALGridView = "OSALGridView";
    public const string TabGroup = "TabGroup";
    public const string Toggle = "Toggle";
    public const string CanvasGroup = "CanvasGroup";
    public const string DragClickPanel = "DragClickPanel";
    public const string UIAni2 = "UIAni2";
    public const string LazyEffectPlayer = "LazyEffectPlayer";
    public const string RedDot = "RedDot";
    public const string MyText = "MyText";
    public const string Text = "Text";
    public const string RawImage = "RawImage";
    public const string Slider = "Slider";
    public const string Scrollbar = "Scrollbar";
    public const string Dropdown = "Dropdown";
    public const string InputField = "InputField";
    public const string Canvas = "Canvas";
    public const string ScrollRect = "ScrollRect";
    public const string SpriteRenderer = "SpriteRenderer";
    public const string Animator = "Animator";
    public const string DOTweenAnimation = "DOTweenAnimation";
    public const string UIDragPinchPanel = "UIDragPinchPanel";
    public const string ParticleSystem = "ParticleSystem";
    public const string UIImageGray = "UIImageGray";
    public const string TMP_InputField = "TMP_InputField";
    public const string BoxCollider = "BoxCollider";
    public const string Tab = "Tab";
    public const string MaterialProgress = "MaterialProgress";
    public const string LPImage = "LPImage";
    public const string Image = "Image";
    public const string UIVideoPlayer = "UIVideoPlayer";
    public const string GameObject = "GameObject";
    public const string LuaUIPolygon = "Polygon";

    //不会自动匹配到：
    public const string DragCardPanel = "DragCardPanel";
    public const string Child = "Child";
    public const string PanelView = "PanelView";
    public const string ContentSizeFitter = "ContentSizeFitter";
    public const string DHText = "DHText";
    public const string EffectCtrl = "EffectCtrl";
    public const string EventTrigger = "EventTrigger";
    public const string LightLayoutGroup = "LightLayoutGroup";
    public const string PieChartMesh = "PieChartMesh";
    public const string RectTransform = "RectTransform";
    public const string SpineAnimaManager = "SpineAnimaManager";
    public const string Transform = "Transform";
    public const string UISkewImage = "UISkewImage";
    public const string UniWebView = "UniWebView";
    public const string OSALScrollViewLazy = "OSALScrollViewLazy";
    public const string OSALGridViewLazy = "OSALGridViewLazy";
}

public class UIControlDataType
{
    /// 已知类型列表，自定义类型可以添加到下面指定区域
    private static List<UIControlDataTypeData> _componentList;
    public static List<UIControlDataTypeData> GetList()
    {
        if (_componentList == null)
        {
            _componentList = new List<UIControlDataTypeData>();
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.HMI_Text,  unityType = typeof(HMI_Text),  helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.HMI_Button,  unityType = typeof(HMI_Button),  helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.HMI_Title,  unityType = typeof(HMI_Title),  helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.HMI_SlideButton,  unityType = typeof(HMI_SlideButton),  helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.HMI_Toggle,  unityType = typeof(HMI_Toggle),  helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.HMI_Slider,  unityType = typeof(HMI_Slider),  helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.HMI_TabGroupBtn,  unityType = typeof(HMI_TabGroupBtn),  helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.HMI_ScrollView,  unityType = typeof(HMI_ScrollView),  helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.HMI_HorizontalItem,  unityType = typeof(HMI_HorizontalItem),  helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.StaticBluredImg,  unityType = typeof(StaticBluredImg),  helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.TextMeshProUGUI,  unityType = typeof(TextMeshProUGUI),  helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.DoubleButton,     unityType = typeof(DoubleButton),     helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.LPButton, unityType = typeof(LPButton), helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Button,           unityType = typeof(Button),           helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.OSALScrollView,   unityType = typeof(OSALScrollView),   helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.OSALGridView,     unityType = typeof(OSALGridView),     helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.TabGroup,         unityType = typeof(TabGroup),         helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Toggle,           unityType = typeof(Toggle),            helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.CanvasGroup,      unityType = typeof(CanvasGroup),      helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.DragClickPanel,   unityType = typeof(UIDragPinchPanel), helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.UIAni2,           unityType = typeof(UIAni2),           helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.LazyEffectPlayer, unityType = typeof(LazyEffectPlayer), helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.RedDot,           unityType = typeof(UIRedDotManager),  helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.MyText, unityType = typeof(MyText), helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Text,             unityType = typeof(Text),             helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.RawImage,         unityType = typeof(RawImage),         helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Slider,           unityType = typeof(Slider),           helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Scrollbar,        unityType = typeof(Scrollbar),        helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Dropdown,         unityType = typeof(Dropdown),         helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.InputField,       unityType = typeof(InputField),       helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Canvas,           unityType = typeof(Canvas),           helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.ScrollRect,       unityType = typeof(ScrollRect),       helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.SpriteRenderer,   unityType = typeof(SpriteRenderer),   helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Animator,         unityType = typeof(Animator),         helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.DOTweenAnimation, unityType = typeof(DOTweenAnimation), helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.UIDragPinchPanel, unityType = typeof(UIDragPinchPanel), helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.ParticleSystem,   unityType = typeof(ParticleSystem),   helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.UIImageGray,      unityType = typeof(UIImageGray),      helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.TMP_InputField,   unityType = typeof(TMP_InputField),   helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.BoxCollider,      unityType = typeof(BoxCollider),      helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Tab,              unityType = typeof(Tab),              helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.MaterialProgress, unityType = typeof(UIMaterialProgressBase), helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.LPImage, unityType = typeof(LPImage), helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Image,            unityType = typeof(Image),            helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.UIVideoPlayer,    unityType = typeof(UIVideoPlayer),    helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.GameObject,       unityType = typeof(GameObject),       helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.LuaUIPolygon,     unityType = typeof(UIPolygon),        helper = new CtrlItemDataDefaultFormatHelper() });

            //不会自动匹配到：
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.DragCardPanel,    unityType = typeof(Transform),        helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Child,            unityType = typeof(GameObject),       helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.PanelView,        unityType = typeof(GameObject),       helper = new CtrlItemDataDefaultFormatHelper() }); //TODO
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.ContentSizeFitter,unityType = typeof(ContentSizeFitter),helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.DHText,           unityType = typeof(DHText),           helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.EffectCtrl,       unityType = typeof(EffectCtrl),       helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.EventTrigger,     unityType = typeof(EventTrigger),     helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.LightLayoutGroup, unityType = typeof(LightLayoutGroup), helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.PieChartMesh,     unityType = typeof(PieChartMesh),     helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.RectTransform,    unityType = typeof(RectTransform),    helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.SpineAnimaManager,unityType = typeof(SpineAnimaManager),helper = new CtrlItemDataDefaultFormatHelper() });
            _componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.Transform,        unityType = typeof(Transform),        helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.UISkewImage,      unityType = typeof(UISkewImage),      helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.UniWebView,       unityType = typeof(UniWebView),       helper = new CtrlItemDataDefaultFormatHelper() 
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.OSALScrollViewLazy,unityType = typeof(OSALScrollView), helper = new CtrlItemDataDefaultFormatHelper() });
            //_componentList.Add(new UIControlDataTypeData { name = EUIControlDataType.OSALGridViewLazy, unityType = typeof(OSALGridView),     helper = new CtrlItemDataDefaultFormatHelper() });
        }

        return _componentList;
    }

    public static int FindType(string target)
    {
        if (_componentList == null)
            GetList();
        
        for (int i = 0, imax = _componentList.Count; i < imax; i++)
        {
            if (_componentList[i].name == target)
                return i;
        }
        return -1;
    }

    public static Dictionary<string, string> LuaNameChange = new Dictionary<string, string>()
    {
        {EUIControlDataType.Text, "Label"},
        {EUIControlDataType.TextMeshProUGUI, "LabelPro"},
        {EUIControlDataType.GameObject, "Panel"},
        {EUIControlDataType.TMP_InputField, "InputFieldPro"},
        {EUIControlDataType.ScrollRect, "ScrollView"},
    };

    public static Dictionary<string, string> BindNameChange = new Dictionary<string, string>()
    {
        {"Active", "ACTIVE"},
        {"Interactable", "BUTTON_INTERACTABLE"},
        {"Lock", "BUTTON_LOCK"},
        {"Select", "BUTTON_SELECT"},
        {"Color", "COLOR"},
        {"Alpha", "ALPHA"},
    };
}
